package xiegd.com.springbootuse.demo.delay1;

/**
 * @Author: xieguangda
 * @Description:
 * @Date: 2023/9/8 16:27
 */
public class Consumer01 {
    //普通交换机名称
    private static final String NORMAL_EXCHANGE = "normal_exchange";
    //死信交换机名称
    private static final String DEAD_EXCHANGE = "dead_exchange";

//    public static void main(String[] argv) throws Exception {
//        Channel channel = RabbitUtils.getChannel();
//        //声明死信和普通交换机 类型为 direct
//        channel.exchangeDeclare(NORMAL_EXCHANGE, BuiltinExchangeType.DIRECT);
//        channel.exchangeDeclare(DEAD_EXCHANGE, BuiltinExchangeType.DIRECT);
//        //声明死信队列
//        String deadQueue = "dead-queue";
//        channel.queueDeclare(deadQueue, false, false, false, null);
//        //死信队列绑定死信交换机与routingkey
//        channel.queueBind(deadQueue, DEAD_EXCHANGE, "lisi");
//        //正常队列绑定死信队列信息
//        Map<String, Object> params = new HashMap<>();
//        //正常队列设置死信交换机 参数 key 是固定值
//        params.put("x-dead-letter-exchange", DEAD_EXCHANGE);
//        //正常队列设置死信 routing-key 参数 key 是固定值
//        params.put("x-dead-letter-routing-key", "lisi");
//        String normalQueue = "normal-queue";
//        channel.queueDeclare(normalQueue, false, false, false, params);
//        channel.queueBind(normalQueue, NORMAL_EXCHANGE, "zhangsan");
//        System.out.println("等待接收消息........... ");
//        DeliverCallback deliverCallback = (consumerTag, delivery) -> {
//            String message = new String(delivery.getBody(), "UTF-8");
//            System.out.println("Consumer01 接收到消息" + message);
//        };
//        channel.basicConsume(normalQueue, true, deliverCallback, consumerTag -> {
//        });
//    }
}
